package com.gogowan.agroenterprise.contorl;

import com.gogowan.agroenterprise.contorl.Enum.Temp;
import com.gogowan.agroenterprise.model.Message;
import com.gogowan.agroenterprise.model.Version;
import com.gogowan.agroenterprise.model.VersionClientInfo;
import com.gogowan.agroenterprise.utils.Utils;

/** @pdOid 67209542-92cd-4153-b6fd-d4bd2bb591bc */
public  class CodeUpdate implements IUpdate {
	private String url="";
	private String result="";
   /** 获取更新信息
    * 
    * @param versioninfo
    * @pdOid f48a9f43-d582-4e51-a451-b4dac0e51c31 */
   public Version getUpdateInfo(VersionClientInfo versioninfo) {
      // TODO: implement
	   Version version=null;
	   try {
		    //version=new Version();
			HTTPCommit commit = new HTTPCommit(getUrl());
		    String json=versioninfo.toJSON(versioninfo);
		    //String encrypt=Utils.encrypt(json);//加密
		    int update=values(Temp.update);
		    Message message=new Message(update,false,json);
		    String jsString = Utils.toJSON(message);
		    
			byte[] b=commit.PostCommit(Utils.toJSON(message),30000);
			if(b!=null)
			{
			   result = new String(b,"utf-8");
			}
			Message m=new Message();
			m=(Message)Utils.fromJSON(result,Message.class);
			setResult(result);
	} catch (NullPointerException  e) {
		// TODO: handle exception
		result="";
	}
	   catch (Exception e) {
		// TODO: handle exception
	}
      return version;
   }
/** @pdOid dfa72f40-862e-45b3-84ff-a8c890bcdc0d */
   public void upgrade() {
      // TODO: implement
		//setPaths(file.getPath());
   }
   
   public int values(Temp str)
   {
   	int id=0;
   	for(Temp t:Temp.values()){
           /*通过getValue()取得相关枚举的值*/
           //System.out.println(t+"的值是"+t.getValue());
           if(t.equals(str))
           {
           	  id=t.getValue();
           }
       }
   	return id;
   }
   
public String getResult() {
	return result;
}
public void setResult(String result) {
	this.result = result;
}
public String getUrl() {
	return url;
}
public void setUrl(String url) {
	this.url = url;
}

   
}